﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Spore.Validator
{
    /// <summary>
    /// 非空字段验证器
    /// </summary>
   public class ValidatorNotNull:ValidatorBase
    {

       private static ValidatorNotNull _default;

        /// <summary>
        /// 默认的验证器
        /// </summary>
       public static ValidatorNotNull Default
        {
            get
            {
                if (_default == null)
                    _default = new ValidatorNotNull();
                return _default;
            }
        }

        private const string DefaultErrMsg = "该内容不能为空";
        /// <summary>       
        /// </summary>        
        /// <param name="errMsg">验证不通过时的错误信息</param>
        public ValidatorNotNull(string errMsg)
            : base(errMsg)
        {
        }
        public ValidatorNotNull()
            : base(DefaultErrMsg)
        {
        }

        #region IValidator部分
        /// <summary>
        ///验证内容必须不为空
        /// </summary>
        /// <param name="content">要验证的内容</param>
        /// <returns></returns>
        public override bool IsValid(Control controlToValidate)
        {
            string content = controlToValidate.Text;
            if (controlToValidate.Text == null) return false;
            return !string.IsNullOrEmpty(controlToValidate.Text.Trim());
        }
        #endregion
      

    }
}
